
/**
 * 过滤器
 */
define(["core","angular"],function(core)
{
	var filters=angular.module("filters",[]);
	
	//格式化日期过滤器
	filters.filter("formatDate",function()
	{
		return function(value,simple)
		{
			var format="";
			if(simple)
			{
				var now_temp=new Date().format("yyyy-MM-dd");
				var value_temp=new Date(value).format("yyyy-MM-dd");
				if(now_temp==value_temp)
					format="hh:mm";
				else
					format="MM-dd";
			}
			return new Date(value).format(format);
		};
	});
	
	//转换为UTF8
	filters.filter("toUTF8",function()
	{
		return function(value)
		{
			return core.util.toUTF8(value);
		}
	});
	
	//摘要
	filters.filter("summary",function()
	{
		return function(value,length)
		{
			if(core.util.isBlank(value))
				return "";
			
			if(core.util.isBlank(length))
				length=20;
			
			if(value.length>length)
				value=value.substring(0,length)+"...";
			
			return value;
		}
	});
	
	//只显示文字
	filters.filter("textOnly",function()
	{
		return function(value)
		{
			if(core.util.isBlank(value))
				return "";
			
			value=core.parser.html("<span>"+value+"</span>");
			return $(value).text();
		}
	});
	
	//返回全路径
	filters.filter("path",function()
	{
		return function(value)
		{
			if(core.util.isBlank(value))
				return "";
			
			return core.System.PATH+value;
		}
	});
	
	//转换到整数
	filters.filter("toInteger",function()
	{
		return function(value)
		{
			if(core.util.isBlank(value))
				return 0;
			
			return parseInt(value);
		}
	});
});